<template>
  <div id="app">
    <div class="box">
      <div class="top" v-show="showheader">
        {{ info.name }}
        <span>
          <i class="iconfont icon-zuojiantou" @click="back()"></i>
        </span>
      </div>
      <div class="icon">
        <i class="iconfont icon-zuojiantou" @click="back()"></i>
      </div>
      <div class="pic">
        <img :src="info.poster" alt="" />
      </div>
      <div class="filmnews">
        <div class="title">
          {{ info.name }}<span>{{ name }}</span>
          <i>{{ info.grade }}</i>
        </div>
        <div class="info">{{ info.category }}</div>
        <div class="info">{{ info.premiereAt | formatDate }}</div>
        <div class="info">{{ info.nation }} | {{ info.runtime }}分钟</div>
        <div class="detailinfo" :class="ishidden ? 'hidden' : ''">
          {{ info.synopsis }}
        </div>
        <div class="iconfont icon-xiajiantou show" @click="show()"></div>
      </div>
      <div class="actor">
        <div class="actortitle">演职人员</div>
        <div class="list">
          <div class="swiper mySwiper">
            <div class="swiper-wrapper">
              <div
                class="swiper-slide"
                v-for="item in info.actors"
                :key="item.name"
              >
                <img :src="item.avatarAddress" width="85" height="100" alt="" />
                <div>{{ item.name }}</div>
                <div class="actorrole">{{ item.role }}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="juzhao">
        <div class="actortitle">剧照</div>
        <div class="empty">暂无电影剧照</div>
      </div>
      <div class="xuanpiao">选座购票</div>
    </div>
  </div>
</template>
<script>
import api from '@/api/index.js'
// 导入swiper
import 'swiper/swiper-bundle.min.css'
import Swiper from 'swiper'
export default {
  data() {
    return {
      info: {},
      name: {},
      ishidden: true,
      showheader: false,
      yanyuan: {}
    }
  },
  methods: {
    back() {
      this.$router.back()
    },
    show() {
      var show = document.querySelector('.box .show[data-v-0e97692a]')
      if (this.ishidden) {
        show.style.transform = 'rotate(180deg)'
      } else {
        show.style.transform = 'rotate(0deg)'
      }
      this.ishidden = !this.ishidden
    }
  },
  created() {
    const id = this.$route.query.id
    this.$http.get(api.getDetail + '?filmId=' + id).then((res) => {
      // console.log(res)
      this.name = res.data.film.filmType.name
      this.yanyuan = res.data.film.actors
      this.info = res.data.film
      const a = this.info.category
      var arr = a.split('|').join('  |  ')
      this.info.category = arr
    })
  },
  mounted() {
    window.addEventListener('scroll', () => {
      const t = document.documentElement.scrollTop || document.body.scrollTop
      if (t > 90) {
        this.showheader = true
      } else {
        this.showheader = false
      }
    })
    /* eslint-disable no-new */
    new Swiper('.mySwiper', {
      slidesPerView: 3,
      spaceBetween: 30,
      freeMode: true
    })
  },
  filters: {
    formatDate: function (val) {
      // const date = val/24
      // console.log(date)
      // return new Date(parseInt(val) * 1000).toLocaleString()
      // return new Date(val * 1000)
      var date = new Date(val * 1000) // 时间戳10为，要*1000
      var year = date.getFullYear()
      var month = date.getMonth() + 1
      var day = date.getDate()
      return year + '-' + month + '-' + day + '上映'
    }
  }
}
</script>
<style lang="scss" scoped>
#app {
  width: 100%;
  height: 100%;
  background-color: #f4f4f4;
}
.box {
  position: relative;
  .top {
    width: 100%;
    height: 44px;
    background-color: #fff;
    text-align: center;
    line-height: 44px;
    font-size: 17px;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 2;
    span {
      position: absolute;
      left: 10px;
      top: 0;
      i {
        font-size: 20px;
      }
    }
  }
  .icon {
    width: 30px;
    height: 30px;
    line-height: 30px;
    position: absolute;
    top: 10px;
    left: 5px;
    background-color: rgba(209, 207, 204, 0.6);
    border-radius: 50%;
    text-align: center;
    i {
      // width: 30px;
      font-size: 23px;
    }
  }
  .pic {
    width: 100%;
    height: 179px;
    overflow: hidden;
    img {
      width: 100%;
    }
  }
  .filmnews {
    padding-top: 15px;
    padding-left: 15px;
    box-sizing: border-box;
    background-color: #fff;
  }
  .info {
    font-size: 13px;
    color: #797d82;
    margin-top: 8px;
  }
  .hidden {
    height: 35px;
    font-size: 13px;
    color: #797d82;
    margin-top: 15px;
  }
  .detailinfo {
    overflow: hidden;
    font-size: 13px;
    color: #797d82;
    margin-top: 15px;
    padding-right: 15px;
    box-sizing: border-box;
  }
  .actor {
    background-color: #fff;
    margin-top: 10px;
    .actortitle {
      padding: 15px;
      font-size: 16px;
      text-align: left;
      color: #191a1b;
    }
    .swiper-slide {
      width: 85px;
      div {
        // text-align: center;
        margin-top: 5px;
        font-size: 10px;
        position: relative;
        left: 25px;
      }
      .actorrole {
        font-size: 10px;
        color: #797d82;
      }
    }
  }
  .juzhao {
    height: 177px;
    background-color: #fff;
    margin-bottom: 50px;
    .actortitle {
      height: 62px;
      padding: 15px;
      font-size: 16px;
      text-align: left;
      color: #191a1b;
    }
    .empty {
      font-size: 14px;
      color: #bdc0c5;
      margin: auto;
      text-align: center;
    }
  }
  .xuanpiao {
    position: fixed;
    bottom: 0;
    left: 0;
    height: 49px;
    width: 100%;
    text-align: center;
    background-color: #ff5f16;
    color: #fff;
    font-size: 16px;
    line-height: 49px;
    z-index: 10;
  }
  .show {
    text-align: center;
    display: block;
    height: auto;
    width: 20px;
    margin: auto;
    line-height: normal;
    color: #797d82;
  }
  .title {
    color: #191a1b;
    font-size: 18px;
    height: 22px;
    line-height: 22px;
    // margin-top: 15px;
    span {
      font-size: 9px;
      color: #fff;
      background-color: #d2d6dc;
      height: 14px;
      line-height: 14px;
      padding: 0 2px;
      border-radius: 2px;
      margin-left: 5px;
      position: relative;
      top: -2px;
    }
    i {
      float: right;
      color: #ffb232;
      font-size: 18px;
      font-style: italic;
      margin-right: 15px;
    }
  }
}

.swiper {
  width: 100%;
  height: 100%;
}
</style>